package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsThreeFloorOutboundDetailsMapper;
import me.zhengjie.pojo.entity.WcsThreeFloorOutboundDetails;
import me.zhengjie.sqlservice.WcsThreeFloorOutboundDetailsService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class WcsThreeFloorOutboundDetailsServiceImpl extends ServiceImpl<WcsThreeFloorOutboundDetailsMapper, WcsThreeFloorOutboundDetails> implements WcsThreeFloorOutboundDetailsService {
    private final WcsThreeFloorOutboundDetailsMapper wcsThreeFloorOutboundDetailsMapper;
    @Override
    public boolean insert(WcsThreeFloorOutboundDetails wcsThreeFloorOutboundDetails) {
        return wcsThreeFloorOutboundDetailsMapper.insert(wcsThreeFloorOutboundDetails) >0;
    }

    @Override
    public WcsThreeFloorOutboundDetails selectContainer(String container) {
        LambdaQueryWrapper<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsThreeFloorOutboundDetailsLambdaQueryWrapper.eq(WcsThreeFloorOutboundDetails::getContainerCode,container);
        return wcsThreeFloorOutboundDetailsMapper.selectOne(wcsThreeFloorOutboundDetailsLambdaQueryWrapper);
    }

    @Override
    public boolean updatePallerCode(Integer id, Integer palletId) {
        LambdaUpdateWrapper<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsThreeFloorOutboundDetailsLambdaUpdateWrapper.set(WcsThreeFloorOutboundDetails::getPalletCode,palletId)
                .set(WcsThreeFloorOutboundDetails::getStatus,1)
                .eq(WcsThreeFloorOutboundDetails::getId,id);
        return wcsThreeFloorOutboundDetailsMapper.update(null,wcsThreeFloorOutboundDetailsLambdaUpdateWrapper) >0;
    }

    @Override
    public List<WcsThreeFloorOutboundDetails> selectPalletCode(String palletCode) {
        LambdaQueryWrapper<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsThreeFloorOutboundDetailsLambdaQueryWrapper.eq(WcsThreeFloorOutboundDetails::getPalletCode,palletCode);
        return wcsThreeFloorOutboundDetailsMapper.selectList(wcsThreeFloorOutboundDetailsLambdaQueryWrapper);
    }

    @Override
    public boolean deleteId(Integer id) {
        return wcsThreeFloorOutboundDetailsMapper.deleteById(id) >0;
    }

    @Override
    public List<WcsThreeFloorOutboundDetails> selectWorkOrder(String workOrder) {
        LambdaQueryWrapper<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsThreeFloorOutboundDetailsLambdaQueryWrapper.eq(WcsThreeFloorOutboundDetails::getWorkOrder,workOrder);
        return wcsThreeFloorOutboundDetailsMapper.selectList(wcsThreeFloorOutboundDetailsLambdaQueryWrapper);
    }

    @Override
    public WcsThreeFloorOutboundDetails selectMechanicalArmLabel(Integer mechanicalArmLabel) {
        LambdaQueryWrapper<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsThreeFloorOutboundDetailsLambdaQueryWrapper.eq(WcsThreeFloorOutboundDetails::getMechanicalArmLabel,mechanicalArmLabel);
        return wcsThreeFloorOutboundDetailsMapper.selectOne(wcsThreeFloorOutboundDetailsLambdaQueryWrapper);
    }

    @Override
    public boolean updateMechanicalArmLabel(String containerCode, Integer mechanicalArmLabel) {
        LambdaUpdateWrapper<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsThreeFloorOutboundDetailsLambdaUpdateWrapper.set(WcsThreeFloorOutboundDetails::getMechanicalArmLabel,mechanicalArmLabel)
                .eq(WcsThreeFloorOutboundDetails::getContainerCode,containerCode);
        return wcsThreeFloorOutboundDetailsMapper.update(null,wcsThreeFloorOutboundDetailsLambdaUpdateWrapper) >0;
    }

    @Override
    public void updateStatusPalletCode(String containerCode, Integer palletCode) {
        LambdaUpdateWrapper<WcsThreeFloorOutboundDetails> wcsThreeFloorOutboundDetailsLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsThreeFloorOutboundDetailsLambdaUpdateWrapper.set(WcsThreeFloorOutboundDetails::getPalletCode,palletCode)
                .set(WcsThreeFloorOutboundDetails::getStatus,1)
                .eq(WcsThreeFloorOutboundDetails::getContainerCode,containerCode);
        wcsThreeFloorOutboundDetailsMapper.update(null,wcsThreeFloorOutboundDetailsLambdaUpdateWrapper);
    }
}
